package xiaoqi.springboot.boot.config;

import io.grpc.Server;
import io.grpc.ServerBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import xiaoqi.springboot.boot.grpc.UserServiceGrpcImpl;

import java.io.IOException;

@Configuration
public class GrpcConfig {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private static final Integer GRPC_PORT = 8888;

    @Bean
    public Server grpcServer(final UserServiceGrpcImpl userServiceGrpc) throws IOException {
        Server server = ServerBuilder.forPort(GRPC_PORT).addService(userServiceGrpc).build();
        server.start();
        logger.info("[gprcServer][启动完成，端口为{}]", server.getPort());
        return server;
    }
}
